package com.dee.components.base.mvp;

import android.content.Context;

import com.dee.components.R;
import com.dee.components.base.ui.AlertDialogBuilder;
import com.dee.components.baserx.RxManager;

/**
 * 作者：kkan on 2017/01/30
 * 当前类注释:
 * 基类presenter
 */
public abstract class BasePresenter<T>{
    public Context mContext;
    public T mView;
    public RxManager mRxManage = new RxManager();
    public BasePresenter presenter = this;

    public void setVM(T v) {
        this.mView = v;
    }
    public void onDestroy() {
        destroyDialogBuilder();
        mRxManage.clear();
    }


    private AlertDialogBuilder dialogBuilder = null;

    public void showDialog(String messageText) {
        creatDialogBuilder().setDialog_message(messageText)
                .setLoadingColor(R.color.red)
                .show();
    }
    public void dismissDialog() {
        if (dialogBuilder != null) {
            dialogBuilder.dismissDialog();
        }
    }

    /**
     * 获取默认Dialog
     */
    private AlertDialogBuilder creatDialogBuilder() {
        if (dialogBuilder == null) {
            dialogBuilder = new AlertDialogBuilder(mContext);
        }
        return dialogBuilder;
    }

    private void destroyDialogBuilder() {
        if (dialogBuilder != null) {
            dialogBuilder.destroyDialogBuilder();
            dialogBuilder = null;
        }
    }
}
